This page last changed on Jan 21, 2009 by fpy.

This page show a typical implementation of a reactor that connects TREX to an external system. To illustrate this I have taken the VCSAdapter class that provide a connection to AUV Linux system using socket connection. The code here can be found under TREX/ctd2007

Reactor expected interface

VCSAdapter.hh
#ifndef H_VCSAdapter
#define H_VCSAdapter

# include "Adapter.hh"

namespace TREX {

  /** @brief Linux Interface to VCS and StatePublisher
   *
   * This class implenments a TREX reactor that provides a connection
   * to VcsServer and StatePublisher.
   *
   * @author Frederic Py <fpy@mbari.org>
   */
  class VCSAdapter: public Adapter {
  public:
    /** @brief Constructor
     *
     * This consdtructor is usually called by the factory that manages
     * configuration parsing
     *
     * @param agentName Name of the agent that will execute this reactor.
     * @param confgData CXonfiguration data for this reactor
     */
    VCSAdapter(LabelStr const &agentName, TiXmlElement const &configData);
    /** @brief Destructor
     */
    ~VCSAdapter();

    /** @brief handle agent initialization signal.
     *
     * This callback is called to indicate to reactors that the agent wait for
     * them to initialize.
     * In this case this is where TREX is initailizing the connections to
     * VCS and wait for feedback from the VCS to be ready to start the misssion.
     *
     * @param initialTick value of the initial tick (usually 0)
     * @param serversByTimeline mapping from timeline name to the connection to its owner
     * @param observer reference to the place where observation of thi reactor should be sent to 
     */
    void handleInit(TICK initialTick, std::map<double, ServerId> const &serversByTimeline, 
		    ObserverId const &observer);
    /** @brief Obsservation production 
     *
     * For uch a reactor this method is called while the agent ex-pect the reactort to produce its new
     * observations. In this case this is whaen the reactor collect all the informations sent from VCS and convert it in
     * @c Observations
     *
     * @retval true if no specific problem
     * @retval false in case of a critical issue
     */
    bool synchronize();
    /** @brief Signal sent  by the agent  to indicate that a new tick has been started
     */
    void handleTickStart();
    /** @brief Notification of a new observation coming from an external agent
     *
     * @note This hould never happen with this reactor as it does not obsserve anything in the agent	
     */
    void notify(Observation const &obs);    
    /** @brief Notification of a goal request
     *
     * This method indicate a new objective received fromn anopther reactor. In the case of this reactor
     * this goal is generally reflecting the execution of a new behavior.
     *
     * @param goal The objective as requested by the reactor
     */
    void handleRequest(GoalId const &goal);
    /** @brief Notification of a goal recall
     *
     * This method indicate to the reactor that a previously requested objective
     * is not part of the plan anymore and should -- if possible -- canceled. 
     *
     * @param goal The objective as requested by the reactor
     */
    void handleRecall(GoalId const &goal);
    
  private:
    /* Internal things specific to this reactor 
     */
    
  }; // TREX::VCSAdapter

} // TREX

#endif // H_VCSAdapter

Declare a new reactor type to the factory

At the beginning of VCSAdapter.cc one can see

namespace TREX {
  namespace {
    DeclareReactor<VCSAdapter> decl("VCSAdapter");
  }
}

This static variable generate a new factory producer that will call the VCSAdapter constructor when it will identify a "VCSAdapter" configuration in the XZML file. For example the following xml file will trigger this :

<Config>
	<!-- Use this component when running onboard -->
	<TeleoReactor name="vcs" component="VCSAdapter"/>

 	<TeleoReactor name="exec" component="DeliberativeReactor" 
		lookAhead="5" latency="1" solverConfig="exec.solver.cfg"/>

	<!-- Skipper has 10 Hour lookahead. -->
 	<TeleoReactor name="skipper" component="DeliberativeReactor" 
		lookAhead="36000" latency="60" solverConfig="skipper.solver.cfg" />
</Config>

What is passed as argument to the constructor is the name of the agent (not showed here) and a C++ representation of the XML field that triggered the creation. In this case:

<TeleoReactor name="vcs" component="VCSAdapter"/>
Document generated by Confluence on Feb 04, 2026 08:05